package com.fatesgo.util;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Response implements Serializable {

    private int code; // 请求状态码
    private String msg; // 返回内容
    private Object data; // 结果数据
    private long total;

    public static <T> Response page(Object data,long total) {
        return Response.builder().code(1).msg("查询成功").data(data).total(total).build();
    }

    public static <T> Response success(String msg) {
        return success(msg, null, 1);
    }

    public static <T> Response success(String msg, Object data) {
        return success(msg, data, 1);
    }

    public static <T> Response success(String msg, Object data, int code) {
        return Response.builder().code(code).msg(msg).data(data).build();
    }

    public static <T> Response error(String msg, Object data, int code) {
        return Response.builder().code(code).msg(msg).data(data).build();
    }

    public static <T> Response error(String msg, Object data) {
        return error(msg, data, 0);
    }

    public static <T> Response error(String msg) {
        return error(msg, null, 0);
    }


}
